package com.dragon.repository.domain.vo;

import com.dragon.common.model.Update;
import com.dragon.common.util.BeanUtils;
import com.dragon.repository.entity.ProductCategory;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;


/**
 * @author sy
 */
@Data
@ApiModel(value = "")
public class ProductCategoryVO {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "类别编号")
    private Integer id;

    @ApiModelProperty(value = "类别名称")
    private String name;

    @ApiModelProperty(value = "状态：1上架2下架")
    private Integer status;

    @ApiModelProperty(value = "优先级")
    private Integer priority;

    @ApiModelProperty(value = "父类别编号")
    private Integer pid;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date createTime;

    @ApiModelProperty(value = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private Date updateTime;

    @ApiModelProperty(value = "公司id")
    private Integer companyId;

    @ApiModelProperty(value = "是否设置默认，0：否 1：是")
    private Integer isDefault;

    @ApiModelProperty(value = "子列表")
    private List<ProductCategory> children;


    @NotNull(groups = Update.class,message = "主键不能为空")
    public static ProductCategory convert(ProductCategoryVO vo) {
        ProductCategory entity = new ProductCategory();
        BeanUtils.copyProperties(vo,entity);
        return entity;
    }
    public static List<ProductCategory> convertList(List<ProductCategoryVO> list) {
        List<ProductCategory> resultList = new ArrayList<>();
        for (ProductCategoryVO vo : list) {
            resultList.add(convert(vo));
        }
        return resultList;
    }
}
